package com.cmcc.aregister.ui.adapter;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.cmcc.aregister.R;
import com.cmcc.aregister.cs.model.NoticeModel;

public class NoticeAdapter extends BaseAdapter {

    private LayoutInflater inflater;
    public List<NoticeModel> list;

    public NoticeAdapter(Context context, List<NoticeModel> list) {
        this.inflater = LayoutInflater.from(context);
        this.list = list;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        MemberHolder holder = null;
        if (convertView == null) {
            holder = new MemberHolder();
            convertView = inflater.inflate(R.layout.notice_list_item, null);
            holder.idView = (TextView) convertView.findViewById(R.id.notice_id);
            holder.titleView = (TextView) convertView.findViewById(R.id.notice_title);
            holder.contentView = (TextView) convertView.findViewById(R.id.notice_content);
            holder.timeView = (TextView) convertView.findViewById(R.id.notice_time);
            convertView.setTag(holder);
        }
        else {
            holder = (MemberHolder) convertView.getTag();
        }
        NoticeModel notice = list.get(position);
        holder.idView.setText(notice.id + "");
        holder.titleView.setText(notice.title);
        holder.contentView.setText(notice.content);
        holder.timeView.setText(notice.create_time);
        return convertView;
    }
    

    static final class MemberHolder {
        TextView idView;
        TextView titleView;
        TextView contentView;
        TextView timeView;
    }

}
